 function exportToExcel(grid, title){
 /**
 * @ grid gridPanel 要导出的grid
 * @ 客户端必须使用IE浏览器，并且安装了Excel2003
 * @ CreatData : 2010-1-20
 */
 //提取grid的列
 var columns = grid.getColumnModel().config.columns ?
     grid.getColumnModel().config.columns :
     grid.getColumnModel().config;

 //提取store以及相关参数
 var store = grid.getStore();
 var colCount = columns.length;//字段数量
 var Cols = new Array(colCount);//为导出字段参数做准备
 var storeCount = store.getCount();//记录数量

 //初始化一个可用ID
 var gridID = grid.getId()+'ExcelObj';

 //OWC的HTML脚本
 var sheetHtml = '<OBJECT id="' + gridID + '" height="100%" width="100%" classid="clsid:0002E559-0000-0000-C000-000000000046"><PARAM NAME="EnableAutoCalculate" VALUE="-1"><PARAM NAME="DisplayTitleBar" VALUE="0"><PARAM NAME="DisplayToolbar" VALUE="-1"><PARAM NAME="ViewableRange" VALUE="1:65536"></OBJECT>';

 var win = new Ext.Window({
    title: 'ExcelWindows',
    closable:true,
    width:600,
    height:500,
    plain:true,
    html:sheetHtml
   });

 win.show(this);

 //从OWC的HTML脚本获得OWC对象
 var xlBook = document.getElementById(gridID);
 var xlsheet = xlBook.ActiveSheet;

 //用grid的数据生成HTML的table
 var tableHtml = "<table><tr><td colspan='" + (colCount - 1) + "'>" + title + "</td></tr><tr>";
 for(var i = 1; i < colCount; i++){//生成表头，并读取列参数
	  tableHtml += "<th width=\"" + columns[i].width + "\">" + columns[i].header + "</th>"
	
	  var col = new Object();
	  col.dateIndex = columns[i].dataIndex;
	  col.renderer = columns[i].renderer;
	  Cols[i] = col;
 }

 tableHtml += "</tr>"

 //生成表格数据体
 for(var i = 0; i < storeCount; i++){
	  var tmpTR = "";
	  tmpTR += "<tr>";
	  for(var j = 1; j < colCount; j++){
	   var date = store.getAt(i);
	   var tmpTD = "";
	   if(columns[j].renderer){
	    tmpTD = "<td>"+ (columns[j].renderer(date.get(columns[j].dataIndex))) +"</td>";
	   }else{
	    tmpTD = "<td>"+ (date.get(columns[j].dataIndex)) +"</td>";
	   }
	   tmpTR += tmpTD;
	  }
	  tmpTR += "</tr>";
	  tableHtml += tmpTR;
 }

 tableHtml += "</table>";

 //将HTML数据绑定给OWC
 xlBook.HTMLData = tableHtml;
 //设置OWC的外观参数
 var xlsheet = xlBook.ActiveSheet;
 xlsheet.Columns.Font.Size = 9;

 //销毁对象
 xlBook=null;
 xlsheet=null;
}